﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DGZImp.MdsProject.Devices.Models;

namespace DGZImp.MdsProject.Devices.Helper
{
    public static class ConvertTools
    {
        public static object ConvertValue(DataTypeEnum type, object val)
        {
            object tmp = null;
            switch (type)
            {
                case DataTypeEnum.None:
                    tmp = val;
                    break;
                case DataTypeEnum.Bool:
                    tmp = Convert.ToBoolean(val);
                    break;
                case DataTypeEnum.Byte:
                    tmp = Convert.ToByte(val);
                    break;
                case DataTypeEnum.Int16:
                    tmp = Convert.ToInt16(val);
                    break;
                case DataTypeEnum.UInt16:
                    tmp = Convert.ToUInt16(val);
                    break;
                case DataTypeEnum.Int32:
                    tmp = Convert.ToInt32(val);
                    break;
                case DataTypeEnum.UInt32:
                    tmp = Convert.ToUInt32(val);
                    break;
                case DataTypeEnum.Int64:
                    tmp = Convert.ToInt64(val);
                    break;
                case DataTypeEnum.UInt64:
                    tmp = Convert.ToUInt64(val);
                    break;
                case DataTypeEnum.Float:
                case DataTypeEnum.Double:
                    tmp = Convert.ToDouble(val);
                    break;
                case DataTypeEnum.String:
                    tmp = Convert.ToString(val);
                    break;
                default:
                    break;
            }
            return tmp;
        }
    }
}
